package com.ruoyi.shop.service;


import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.ruoyi.shop.config.AlipayConfig1;
import com.ruoyi.shop.domain.AlipayBean;
import org.springframework.stereotype.Service;

@Service
public class AlipayServiceImpl implements AlipayService {
    @Override
    public String aliPay(AlipayBean alipayBean) throws AlipayApiException {
        //获得初始化的AlipayClient
            AlipayClient alipayClient = new DefaultAlipayClient(
                    AlipayConfig1.gatewayUrl,
                    AlipayConfig1.appId,
                    AlipayConfig1.privateKey,
                    "json",
                    AlipayConfig1.charset,
                    AlipayConfig1.publicKey,
                    AlipayConfig1.signType);
            //设置请求参数
      //  AlipayTradePayModel
       // AlipayTradeAppPayRequest alipayRequest = new AlipayTradeAppPayRequest();
        AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
           //AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setNotifyUrl(AlipayConfig1.notify_url);
        alipayRequest.setReturnUrl(AlipayConfig1.returnUrl);

        System.out.println(JSON.toJSONString(alipayBean));
            alipayRequest.setBizContent(JSON.toJSONString(alipayBean));  //把对象转换成JSON字符串
            //请求
      //  AlipayTradeAppPayResponse response = alipayClient.sdkExecute(alipayRequest);
        //  String result = response.getBody();
         String result = alipayClient.pageExecute(alipayRequest).getBody();

        System.out.println(result+"      Service里的东西");
        return result;
    }
}
